﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ObjectManager;

namespace QuanLyDiem
{
    public partial class frmBoMon_Them : Form
    {
        private static frmBoMon_Them frm = null;

        private frmBoMon_Them()
        {
            InitializeComponent();
        }

        public static frmBoMon_Them Create()
        {
            return Create(false);
        }

        public static frmBoMon_Them Create(bool child)
        {
            if (frm == null)
            {
                frm = new frmBoMon_Them();
            }
            if (child)
            {
                frm.ControlBox = false;
                frm.MinimizeBox = false;
                frm.MaximizeBox = false;
                frm.WindowState = FormWindowState.Maximized;
            }
            return frm;
        }

        private void frmBoMon_Them_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (frm != null)
            {
                frm.Dispose();
                frm = null;
            }
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            ClearText();
        }

        private void ClearText()
        {
            txtKyHieu.Text = "";
            txtTen.Text = "";
            txtMa.Text = (new BoMon()).Ma().ToString();
        }
        private void btnThem_Click(object sender, EventArgs e)
        {
            BoMon bomon = new BoMon();
            bomon.ThongTin.KyHieu = txtKyHieu.Text.Trim().ToUpper();
            bomon.ThongTin.Ten = txtTen.Text.Trim();
            if (bomon.Add() > 0)
            {
                MessageBox.Show("Đã thêm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ClearText();
            }
            else
            {
                MessageBox.Show("Không thêm được", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void frmBoMon_Them_Load(object sender, EventArgs e)
        {
            ClearText();
        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }
    }
}
